package com.yu.dv.strategy.metadata;

import com.yu.dv.strategy.AbstractStrategyFactory;
import com.yu.dv.strategy.metadata.impl.*;

/**
 * 元数据策略工厂实现
 */
public class MetadataStrategyFactory extends AbstractStrategyFactory<MetadataStrategy> {

    private MetadataStrategyFactory() {
        super("MetadataStrategyFactory");
        initialize(); // 构造函数中初始化
    }

    private static class Holder {
        private static final MetadataStrategyFactory INSTANCE = new MetadataStrategyFactory();
    }

    public static MetadataStrategyFactory getInstance() {
        return Holder.INSTANCE;
    }

    @Override
    public void initialize() {
        // 注册所有策略（按优先级排序）
        registerStrategy("mysql", new MySQLMetadataStrategy());
        registerStrategy("postgresql", new PostgreSQLMetadataStrategy());
        registerStrategy("oracle", new OracleMetadataStrategy());
        registerStrategy("sqlserver", new SQLServerMetadataStrategy());
        registerStrategy("h2", new H2MetadataStrategy());
        registerStrategy("all", new GenericMetadataStrategy());

        // 注册别名
        registerStrategy("mariadb", strategies.get("mysql"));
        registerStrategy("mssql", strategies.get("sqlserver"));
        registerStrategy("postgres", strategies.get("postgresql"));
    }

    @Override
    protected MetadataStrategy getDefaultStrategy() {
        // 返回通用策略作为默认
        return strategies.get("all");
    }

    @Override
    public MetadataStrategy getStrategy(String databaseProductName) {
       return strategies.get(databaseProductName.toLowerCase());
    }
}